package com.mccrea.pattern.singleton.type5;

/**
 * @Classname SingleTonTest05
 * @Description 单例模式 双重检查 测试
 * @Date 2021/5/7 0007 15:07
 * @Created by Mccrea_Gao
 */
public class SingleTonTest05 {
    public static void main(String[] args) {

    }
}

/**
 * 单例模式 双重检查
 */
class SingleTon05 {
    private SingleTon05() {

    }
    private static volatile SingleTon05 instance;

    public static SingleTon05 getInstance() {
        if (instance == null) {
            synchronized (SingleTon05.class) {
                if (instance == null) {
                    instance = new SingleTon05();
                }
            }
        }
        return instance;
    }
}
